package com.zb.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.AccounLoginInfo;
import com.zb.entity.ZjWorkReservationLog;
import com.zb.mapper.ZjWorkReservationLogMapper;
import com.zb.service.ZjWorkReservationLogService;
import com.zb.vo.WorkReservationLogVo;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 工单预约记录表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-16
 */
@Service
public class ZjWorkReservationLogServiceImpl extends ServiceImpl<ZjWorkReservationLogMapper, ZjWorkReservationLog> implements ZjWorkReservationLogService {

    // 保存客服预约时间
    @Override
    public void saveService(AccounLoginInfo logintInfo, WorkReservationLogVo reservationLogVo) {
        save(logintInfo, 1, reservationLogVo);
    }

    // 保存服务商预约时间
    @Override
    public void saveNetwork(AccounLoginInfo logintInfo, WorkReservationLogVo reservationLogVo) {
        save(logintInfo, 2, reservationLogVo);
    }

    // 保存工程师预约时间
    @Override
    public void saveNetworkEngineer(AccounLoginInfo logintInfo, WorkReservationLogVo reservationLogVo) {
        save(logintInfo, 3, reservationLogVo);
    }

    private void save(AccounLoginInfo logintInfo, Integer type, WorkReservationLogVo reservationLogVo) {
        ZjWorkReservationLog log = new ZjWorkReservationLog();
        BeanUtil.copyProperties(reservationLogVo, log);
        log.setId(IdWorker.getId())
                .setCustAccId(logintInfo.getCustAccId())
                .setType(type)
                .setCreateEmp(logintInfo.getName())
                .setRemark(StringUtils.isNotBlank(log.getRemark())? log.getRemark(): "");
        this.save(log);
    }


}
